1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.EntryCompletion; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.c.functions; 30 private import gobject.ObjectG; 31 private import gobject.Signals; 32 private import gtk.BuildableIF; 33 private import gtk.BuildableT; 34 private import gtk.CellArea; 35 private import gtk.CellLayoutIF; 36 private import gtk.CellLayoutT; 37 private import gtk.TreeIter; 38 private import gtk.TreeModelIF; 39 private import gtk.Widget; 40 private import gtk.c.functions; 41 public import gtk.c.types; 42 private import std.algorithm; 43 44 45 /** 46 * `GtkEntryCompletion` is an auxiliary object to provide completion functionality 47 * for `GtkEntry`. 48 * 49 * It implements the [iface@Gtk.CellLayout] interface, to allow the user 50 * to add extra cells to the `GtkTreeView` with completion matches. 51 * 52 * “Completion functionality” means that when the user modifies the text 53 * in the entry, `GtkEntryCompletion` checks which rows in the model match 54 * the current content of the entry, and displays a list of matches. 55 * By default, the matching is done by comparing the entry text 56 * case-insensitively against the text column of the model (see 57 * [method@Gtk.EntryCompletion.set_text_column]), but this can be overridden 58 * with a custom match function (see [method@Gtk.EntryCompletion.set_match_func]). 59 * 60 * When the user selects a completion, the content of the entry is 61 * updated. By default, the content of the entry is replaced by the 62 * text column of the model, but this can be overridden by connecting 63 * to the [signal@Gtk.EntryCompletion::match-selected] signal and updating the 64 * entry in the signal handler. Note that you should return %TRUE from 65 * the signal handler to suppress the default behaviour. 66 * 67 * To add completion functionality to an entry, use 68 * [method@Gtk.Entry.set_completion]. 69 * 70 * `GtkEntryCompletion` uses a [class@Gtk.TreeModelFilter] model to 71 * represent the subset of the entire model that is currently matching. 72 * While the `GtkEntryCompletion` signals 73 * [signal@Gtk.EntryCompletion::match-selected] and 74 * [signal@Gtk.EntryCompletion::cursor-on-match] take the original model 75 * and an iter pointing to that model as arguments, other callbacks and 76 * signals (such as `GtkCellLayoutDataFunc` or 77 * [signal@Gtk.CellArea::apply-attributes)] 78 * will generally take the filter model as argument. As long as you are 79 * only calling [method@Gtk.TreeModel.get], this will make no difference to 80 * you. If for some reason, you need the original model, use 81 * [method@Gtk.TreeModelFilter.get_model]. Don’t forget to use 82 * [method@Gtk.TreeModelFilter.convert_iter_to_child_iter] to obtain a 83 * matching iter. 84 */ 85 public class EntryCompletion : ObjectG, BuildableIF, CellLayoutIF 86 { 87 /** the main Gtk struct */ 88 protected GtkEntryCompletion* gtkEntryCompletion; 89 90 /** Get the main Gtk struct */ 91 public GtkEntryCompletion* getEntryCompletionStruct(bool transferOwnership = false) 92 { 93 if (transferOwnership) 94 ownedRef = false; 95 return gtkEntryCompletion; 96 } 97 98 /** the main Gtk struct as a void* */ 99 protected override void* getStruct() 100 { 101 return cast(void*)gtkEntryCompletion; 102 } 103 104 /** 105 * Sets our main struct and passes it to the parent class. 106 */ 107 public this (GtkEntryCompletion* gtkEntryCompletion, bool ownedRef = false) 108 { 109 this.gtkEntryCompletion = gtkEntryCompletion; 110 super(cast(GObject*)gtkEntryCompletion, ownedRef); 111 } 112 113 // add the Buildable capabilities 114 mixin BuildableT!(GtkEntryCompletion); 115 116 // add the CellLayout capabilities 117 mixin CellLayoutT!(GtkEntryCompletion); 118 119 120 /** */ 121 public static GType getType() 122 { 123 return gtk_entry_completion_get_type(); 124 } 125 126 /** 127 * Creates a new `GtkEntryCompletion` object. 128 * 129 * Returns: A newly created `GtkEntryCompletion` object 130 * 131 * Throws: ConstructionException GTK+ fails to create the object. 132 */ 133 public this() 134 { 135 auto __p = gtk_entry_completion_new(); 136 137 if(__p is null) 138 { 139 throw new ConstructionException("null returned by new"); 140 } 141 142 this(cast(GtkEntryCompletion*) __p, true); 143 } 144 145 /** 146 * Creates a new `GtkEntryCompletion` object using the 147 * specified @area. 148 * 149 * The `GtkCellArea` is used to layout cells in the underlying 150 * `GtkTreeViewColumn` for the drop-down menu. 151 * 152 * Params: 153 * area = the `GtkCellArea` used to layout cells 154 * 155 * Returns: A newly created `GtkEntryCompletion` object 156 * 157 * Throws: ConstructionException GTK+ fails to create the object. 158 */ 159 public this(CellArea area) 160 { 161 auto __p = gtk_entry_completion_new_with_area((area is null) ? null : area.getCellAreaStruct()); 162 163 if(__p is null) 164 { 165 throw new ConstructionException("null returned by new_with_area"); 166 } 167 168 this(cast(GtkEntryCompletion*) __p, true); 169 } 170 171 /** 172 * Requests a completion operation, or in other words a refiltering of the 173 * current list with completions, using the current key. 174 * 175 * The completion list view will be updated accordingly. 176 */ 177 public void complete() 178 { 179 gtk_entry_completion_complete(gtkEntryCompletion); 180 } 181 182 /** 183 * Computes the common prefix that is shared by all rows in @completion 184 * that start with @key. 185 * 186 * If no row matches @key, %NULL will be returned. 187 * Note that a text column must have been set for this function to work, 188 * see [method@Gtk.EntryCompletion.set_text_column] for details. 189 * 190 * Params: 191 * key = The text to complete for 192 * 193 * Returns: The common prefix all rows 194 * starting with @key 195 */ 196 public string computePrefix(string key) 197 { 198 auto retStr = gtk_entry_completion_compute_prefix(gtkEntryCompletion, Str.toStringz(key)); 199 200 scope(exit) Str.freeString(retStr); 201 return Str.toString(retStr); 202 } 203 204 /** 205 * Get the original text entered by the user that triggered 206 * the completion or %NULL if there’s no completion ongoing. 207 * 208 * Returns: the prefix for the current completion 209 */ 210 public string getCompletionPrefix() 211 { 212 return Str.toString(gtk_entry_completion_get_completion_prefix(gtkEntryCompletion)); 213 } 214 215 /** 216 * Gets the entry @completion has been attached to. 217 * 218 * Returns: The entry @completion has been attached to 219 */ 220 public Widget getEntry() 221 { 222 auto __p = gtk_entry_completion_get_entry(gtkEntryCompletion); 223 224 if(__p is null) 225 { 226 return null; 227 } 228 229 return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p); 230 } 231 232 /** 233 * Returns whether the common prefix of the possible completions should 234 * be automatically inserted in the entry. 235 * 236 * Returns: %TRUE if inline completion is turned on 237 */ 238 public bool getInlineCompletion() 239 { 240 return gtk_entry_completion_get_inline_completion(gtkEntryCompletion) != 0; 241 } 242 243 /** 244 * Returns %TRUE if inline-selection mode is turned on. 245 * 246 * Returns: %TRUE if inline-selection mode is on 247 */ 248 public bool getInlineSelection() 249 { 250 return gtk_entry_completion_get_inline_selection(gtkEntryCompletion) != 0; 251 } 252 253 /** 254 * Returns the minimum key length as set for @completion. 255 * 256 * Returns: The currently used minimum key length 257 */ 258 public int getMinimumKeyLength() 259 { 260 return gtk_entry_completion_get_minimum_key_length(gtkEntryCompletion); 261 } 262 263 /** 264 * Returns the model the `GtkEntryCompletion` is using as data source. 265 * 266 * Returns %NULL if the model is unset. 267 * 268 * Returns: A `GtkTreeModel` 269 */ 270 public TreeModelIF getModel() 271 { 272 auto __p = gtk_entry_completion_get_model(gtkEntryCompletion); 273 274 if(__p is null) 275 { 276 return null; 277 } 278 279 return ObjectG.getDObject!(TreeModelIF)(cast(GtkTreeModel*) __p); 280 } 281 282 /** 283 * Returns whether the completions should be presented in a popup window. 284 * 285 * Returns: %TRUE if popup completion is turned on 286 */ 287 public bool getPopupCompletion() 288 { 289 return gtk_entry_completion_get_popup_completion(gtkEntryCompletion) != 0; 290 } 291 292 /** 293 * Returns whether the completion popup window will be resized to the 294 * width of the entry. 295 * 296 * Returns: %TRUE if the popup window will be resized to the width of 297 * the entry 298 */ 299 public bool getPopupSetWidth() 300 { 301 return gtk_entry_completion_get_popup_set_width(gtkEntryCompletion) != 0; 302 } 303 304 /** 305 * Returns whether the completion popup window will appear even if there is 306 * only a single match. 307 * 308 * Returns: %TRUE if the popup window will appear regardless of the 309 * number of matches 310 */ 311 public bool getPopupSingleMatch() 312 { 313 return gtk_entry_completion_get_popup_single_match(gtkEntryCompletion) != 0; 314 } 315 316 /** 317 * Returns the column in the model of @completion to get strings from. 318 * 319 * Returns: the column containing the strings 320 */ 321 public int getTextColumn() 322 { 323 return gtk_entry_completion_get_text_column(gtkEntryCompletion); 324 } 325 326 /** 327 * Requests a prefix insertion. 328 */ 329 public void insertPrefix() 330 { 331 gtk_entry_completion_insert_prefix(gtkEntryCompletion); 332 } 333 334 /** 335 * Sets whether the common prefix of the possible completions should 336 * be automatically inserted in the entry. 337 * 338 * Params: 339 * inlineCompletion = %TRUE to do inline completion 340 */ 341 public void setInlineCompletion(bool inlineCompletion) 342 { 343 gtk_entry_completion_set_inline_completion(gtkEntryCompletion, inlineCompletion); 344 } 345 346 /** 347 * Sets whether it is possible to cycle through the possible completions 348 * inside the entry. 349 * 350 * Params: 351 * inlineSelection = %TRUE to do inline selection 352 */ 353 public void setInlineSelection(bool inlineSelection) 354 { 355 gtk_entry_completion_set_inline_selection(gtkEntryCompletion, inlineSelection); 356 } 357 358 /** 359 * Sets the match function for @completion to be @func. 360 * 361 * The match function is used to determine if a row should or 362 * should not be in the completion list. 363 * 364 * Params: 365 * func = the `GtkEntryCompletion`MatchFunc to use 366 * funcData = user data for @func 367 * funcNotify = destroy notify for @func_data. 368 */ 369 public void setMatchFunc(GtkEntryCompletionMatchFunc func, void* funcData, GDestroyNotify funcNotify) 370 { 371 gtk_entry_completion_set_match_func(gtkEntryCompletion, func, funcData, funcNotify); 372 } 373 374 /** 375 * Requires the length of the search key for @completion to be at least 376 * @length. 377 * 378 * This is useful for long lists, where completing using a small 379 * key takes a lot of time and will come up with meaningless results anyway 380 * (ie, a too large dataset). 381 * 382 * Params: 383 * length = the minimum length of the key in order to start completing 384 */ 385 public void setMinimumKeyLength(int length) 386 { 387 gtk_entry_completion_set_minimum_key_length(gtkEntryCompletion, length); 388 } 389 390 /** 391 * Sets the model for a `GtkEntryCompletion`. 392 * 393 * If @completion already has a model set, it will remove it 394 * before setting the new model. If model is %NULL, then it 395 * will unset the model. 396 * 397 * Params: 398 * model = the `GtkTreeModel` 399 */ 400 public void setModel(TreeModelIF model) 401 { 402 gtk_entry_completion_set_model(gtkEntryCompletion, (model is null) ? null : model.getTreeModelStruct()); 403 } 404 405 /** 406 * Sets whether the completions should be presented in a popup window. 407 * 408 * Params: 409 * popupCompletion = %TRUE to do popup completion 410 */ 411 public void setPopupCompletion(bool popupCompletion) 412 { 413 gtk_entry_completion_set_popup_completion(gtkEntryCompletion, popupCompletion); 414 } 415 416 /** 417 * Sets whether the completion popup window will be resized to be the same 418 * width as the entry. 419 * 420 * Params: 421 * popupSetWidth = %TRUE to make the width of the popup the same as the entry 422 */ 423 public void setPopupSetWidth(bool popupSetWidth) 424 { 425 gtk_entry_completion_set_popup_set_width(gtkEntryCompletion, popupSetWidth); 426 } 427 428 /** 429 * Sets whether the completion popup window will appear even if there is 430 * only a single match. 431 * 432 * You may want to set this to %FALSE if you 433 * are using [property@Gtk.EntryCompletion:inline-completion]. 434 * 435 * Params: 436 * popupSingleMatch = %TRUE if the popup should appear even for a single match 437 */ 438 public void setPopupSingleMatch(bool popupSingleMatch) 439 { 440 gtk_entry_completion_set_popup_single_match(gtkEntryCompletion, popupSingleMatch); 441 } 442 443 /** 444 * Convenience function for setting up the most used case of this code: a 445 * completion list with just strings. 446 * 447 * This function will set up @completion 448 * to have a list displaying all (and just) strings in the completion list, 449 * and to get those strings from @column in the model of @completion. 450 * 451 * This functions creates and adds a `GtkCellRendererText` for the selected 452 * column. If you need to set the text column, but don't want the cell 453 * renderer, use g_object_set() to set the 454 * [property@Gtk.EntryCompletion:text-column] property directly. 455 * 456 * Params: 457 * column = the column in the model of @completion to get strings from 458 */ 459 public void setTextColumn(int column) 460 { 461 gtk_entry_completion_set_text_column(gtkEntryCompletion, column); 462 } 463 464 /** 465 * Emitted when a match from the cursor is on a match of the list. 466 * 467 * The default behaviour is to replace the contents 468 * of the entry with the contents of the text column in the row 469 * pointed to by @iter. 470 * 471 * Note that @model is the model that was passed to 472 * [method@Gtk.EntryCompletion.set_model]. 473 * 474 * Params: 475 * model = the `GtkTreeModel` containing the matches 476 * iter = a `GtkTreeIter` positioned at the selected match 477 * 478 * Returns: %TRUE if the signal has been handled 479 */ 480 gulong addOnCursorOnMatch(bool delegate(TreeModelIF, TreeIter, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 481 { 482 return Signals.connect(this, "cursor-on-match", dlg, connectFlags ^ ConnectFlags.SWAPPED); 483 } 484 485 /** 486 * Emitted when the inline autocompletion is triggered. 487 * 488 * The default behaviour is to make the entry display the 489 * whole prefix and select the newly inserted part. 490 * 491 * Applications may connect to this signal in order to insert only a 492 * smaller part of the @prefix into the entry - e.g. the entry used in 493 * the `GtkFileChooser` inserts only the part of the prefix up to the 494 * next '/'. 495 * 496 * Params: 497 * prefix = the common prefix of all possible completions 498 * 499 * Returns: %TRUE if the signal has been handled 500 */ 501 gulong addOnInsertPrefix(bool delegate(string, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 502 { 503 return Signals.connect(this, "insert-prefix", dlg, connectFlags ^ ConnectFlags.SWAPPED); 504 } 505 506 /** 507 * Emitted when a match from the list is selected. 508 * 509 * The default behaviour is to replace the contents of the 510 * entry with the contents of the text column in the row 511 * pointed to by @iter. 512 * 513 * Note that @model is the model that was passed to 514 * [method@Gtk.EntryCompletion.set_model]. 515 * 516 * Params: 517 * model = the `GtkTreeModel` containing the matches 518 * iter = a `GtkTreeIter` positioned at the selected match 519 * 520 * Returns: %TRUE if the signal has been handled 521 */ 522 gulong addOnMatchSelected(bool delegate(TreeModelIF, TreeIter, EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 523 { 524 return Signals.connect(this, "match-selected", dlg, connectFlags ^ ConnectFlags.SWAPPED); 525 } 526 527 /** 528 * Emitted when the filter model has zero 529 * number of rows in completion_complete method. 530 * 531 * In other words when `GtkEntryCompletion` is out of suggestions. 532 */ 533 gulong addOnNoMatches(void delegate(EntryCompletion) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 534 { 535 return Signals.connect(this, "no-matches", dlg, connectFlags ^ ConnectFlags.SWAPPED); 536 } 537 }